//
//  CustomPhotoAlbumCell.m
//  WeCommunity
//
//  Created by mac on 2017/6/19.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "CustomPhotoAlbumCell.h"
#import "PhotoAlbumModel.h"

@interface CustomPhotoAlbumCell ()<ChoosePhotoDelegate>

@property (nonatomic,strong)NSMutableArray * imageViewArray;

@property (nonatomic,strong)NSMutableArray * photoModelArray;

@end


@implementation CustomPhotoAlbumCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        self.imageViewArray = [NSMutableArray array];
        
        CGFloat width = (KScreen_Width - 25) / 4;
        
        for (int i = 0; i < 4; i++) {
            ChoosePhotoView * photoView = [[ChoosePhotoView alloc] initWithFrame:CGRectMake(5 + (5 + width) * i, 5, width, width)];
            photoView.delegate = self;
            [self.contentView addSubview:photoView];
            [self.imageViewArray addObject:photoView];
        }
    }
    return self;
}

-(void)layoutViewWithModels:(NSArray *)models
{
    self.photoModelArray = [models mutableCopy];
    for (int i = 0; i < self.imageViewArray.count; i++) {
        ChoosePhotoView * photoView = self.imageViewArray[i];
        if (i < self.photoModelArray.count) {
            photoView.hidden = NO;
            PhotoAlbumModel * photoModel = self.photoModelArray[i];
            photoView.photoAlbumModel = photoModel;
        }else{
            photoView.hidden = YES;
        }
    }
}

#pragma mark - delegate
-(void)preViewPhotoAlbum:(PhotoAlbumModel *)albumModel
{
    if (self.delegate) {
        [self.delegate preViewPhotoAlbum:albumModel];
    }
}

-(void)choosePhotoAlbum:(PhotoAlbumModel *)albumModel sender:(UIButton *)sender
{
    if (self.delegate) {
        [self.delegate choosePhotoAlbum:albumModel sender:sender];
    }
}


@end
